package net.niufei.study.patterns.fundamental;

public class Proxy {
	
	
	static IService createService() {
		return new ServiceProxy(new Service());
	}
	

	interface IService {
		void service();
	}
	
	
	
	static class Service implements IService {

		@Override
		public void service() {
			System.out.println("service something");
		}
		
	}
	
	
	
	static class ServiceProxy implements IService {
		private IService delegate;
		
		public ServiceProxy(IService delegate) {
			this.delegate = delegate;
		}

		@Override
		public void service() {
			System.out.println("before service");
			delegate.service();
			System.out.println("after service");
		}
		
	}
	
	
	public static void main(String[] args) {
		IService service = Proxy.createService();
		service.service();
	}
}
